package cn.com.utils;

import java.io.ByteArrayInputStream;
import java.util.Iterator;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class Analysis {

	/**
	 * 字符解析工具类
	 * 
	 * @param content
	 *            拿到的数据 : User [id=1182391231, screenName=null, name=null,
	 *            province=0, city=0, location=null, description=null, url=null,
	 *            profileImageUrl=null, userDomain=null, gender=null,
	 *            followersCount=0, friendsCount=0, statusesCount=0,
	 *            favouritesCount=0, createdAt=null, following=false,
	 *            verified=false, verifiedType=0, allowAllActMsg=false,
	 *            allowAllComment=false, followMe=false, avatarLarge=null,
	 *            onlineStatus=0, status=null, biFollowersCount=0, remark=房地产,
	 *            lang=null, verifiedReason=null]
	 * @return 返回拼接好的字符串 1182391231\tnull\tnull....
	 */
	public static String analysisToUser(String content) {
		// 去掉首尾 User[]
		content = content.substring(6, 468);
		// ,号分割
		String[] results = content.split(",");
		// 记录最终结果集
		String resultLast = "";
		for (String result : results) {
			String[] values = result.split("=");
			// 拼接最后的字符串
			resultLast += (values[1] + "\t");
		}
		return resultLast;
	}

	/**
	 * xml 解析工具类
	 * 
	 * @param content
	 *            拿到的数据 <comment><content>2014年可以使用，中国中心在64层到69层共2万平米
	 *            //@禾臣薛朝阳:#中国中心#也盖出来了？@许立-VANTONE</content><time>2012-4-3
	 *            11:30:
	 *            08</time><repostsCount>8</repostsCount><commentsCount>4</
	 *            commentsCount></comment>
	 * @return 返回拼接好的字符串
	 * @throws Exception
	 */
	public static String analysisToContent(String input) throws Exception {
		// 创建SAXReader
		// SAXReader reader = new SAXReader();

		Document document = DocumentHelper.parseText(input);

		// 获取根节点
		Element root = document.getRootElement();

		// 记录最终结果集
		String resultLast = "";

		// System.out.println(root.elementText("content"));
		// System.out.println(root.elementText("time"));
		// System.out.println(root.elementText("repostsCount"));
		// System.out.println(root.elementText("commentsCount"));
		// 拼接最后的字符串
		resultLast = resultLast + root.elementText("content") + "\t";
		resultLast = resultLast + root.elementText("time") + "\t";
		resultLast = resultLast + root.elementText("repostsCount") + "\t";
		resultLast = resultLast + root.elementText("commentsCount");

		return resultLast;
	}
}
